<?php
  // 商品信息
  $products = array(
    array("id"=>"1" ,"name"=>"可可芭蕾" ,"price"=>13.00),
    array("id"=>"2" ,"name"=>"阿华田" ,"price"=>17.00),
    array("id"=>"3" ,"name"=>"冰淇淋红茶" ,"price"=>8.00),
    array("id"=>"4" ,"name"=>"百香三重奏" ,"price"=>15.00)
  );

  session_start(); // 初始化Session

  if(!empty($_SESSION['cart'])){
    $order = $_SESSION['cart'];
    $sum = array_sum(array_column($order, "num")); // 统计购物车内的商品数量
  }else{
    $sum=0; 
  }
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
  <title>商品列表</title>
  <link rel="stylesheet" href="./css/style.css">
</head>
<body>
	<div class="container">
		<h1>商品列表</h1>
		<hr>
		<table>
			<tr>
				<th>商品名</th>
				<th>售价</th>
				<th>购物车</th>
			</tr>
			<!-- 遍历商品数组，显示商品信息 -->
			<?php foreach ($products as $key => $value) :?>  <!-- 第（3）空 -->
			<tr>
				<td><?php echo $value['name'] ?></td>
				<!-- 商品名 -->
				<td class="price">￥<?php echo $value['price'] ?></td>
				<!-- 售价 -->
				<td><a class="btn" title="添加到购物车" href="addCart.php?upd=add&id=<?php echo $value['id']; ?>&name=<?php echo $value['name']; ?>&price=<?php echo $value['price']; ?>">+</a></td> <!-- 第（4）空 -->
			</tr>
			<?php endforeach; ?>
		</table>
		<!-- 显示购物车内的总商品数 -->
		<div class="cart-count">
			<div class="count">
				您总共选择了<span class="goods-nums"><?php echo $sum;?></span>件商品
			</div>			
			<a class="to-cart" title="跳转到我的购物车" href="cart.php?upd=cart">→购物车</a>  <!-- 第（4）空 -->
		</div>
	</div>
</body>
</html>